#ifndef JOBSWORKER_H
#define JOBSWORKER_H

namespace bimar_scheduler_lib
{

class CJobsWorker : public CGThreadWrapper
{
protected:
  typedef std::list<CJob *> JobList;
  typedef JobList::iterator JobIt;

  typedef std::list<CJobExecutor *> JobExecutorList;
  typedef JobExecutorList::iterator JobExecutorIt;

public:
  CJobsWorker();
  virtual ~CJobsWorker();

  /* CJobsWorker interface */
  virtual gboolean Create();
  virtual gboolean Destroy();
  virtual gboolean Start();
  virtual gboolean Stop();  

  /* job list manipulation */
  gboolean AddJob(CJob *job);    

protected:
  /* CJobsWorker interface */
  virtual gulong RunThread() = 0;
  
  CJob * GetNextJobToExecute();
  gboolean StartJob(CJobExecutor *executor, CJob *job);  
  gboolean DestroyJobs();
  gboolean DestroyExecutors();

protected:
  JobExecutorList m_jobExec;				//!< The JobExecutor list
  CGCriticalSectionWrapper m_jobExecCS;		//!< Critical section for the JobExecutor list      
  JobList  m_jobs;							//!< All the jobs. Owner
  CGCriticalSectionWrapper m_jobsCS;        //!< Critical section for the Job list
  JobList  m_submittedJobList;              //!< submited. references from main job list
  JobList  m_runningJobList;                //!< running. references from main job list
  JobList  m_doneJobList;                   //!< done. references from main job list
};

}; /* namespace */

#endif // JOBSWORKER_H
